var hfck_app = function(){
	var path = Constants.amUrlPath;
	var id = manager.findParamFromUrl('id');//意见反馈ID
	var wtzt = manager.findParamFromUrl('wtzt');//处理状态(0-已处理,1-未处理)
	var hfckRactive,ue;
	hfckApp={
		URL:{
			yjfkxx: function(id){//根据ID获取意见反馈信息路径post
				return path + "yjfk/getYjfkById?id=" + id;
			},
			save: function(){//回复处理保存路径post
				return path + "yjfk/updateYjfk";
			}
		},
		getYjfkxxById: function(id,wtzt,ractive){
			 $.ajax({
				type: "get",
				url: hfckApp.URL.yjfkxx(id),				
				async: false,
				success: function(data) {//数据绑定
					//console.log(data);
					ractive.set("yjfkxx",data);
					if(wtzt == Constants.code.WTZT.WTZT_YCL){// 如果状态=0，已处理
						$('#title').text('查看');
						$("#hffknr1").hide();
						$("#hffknr2").show();
						$('.hp-btnp-qr').hide();
						$('.hp-btnp-qx').hide();
					}
					if(wtzt == Constants.code.WTZT.WTZT_WCL){//如果状态=1，未处理
						$('#title').text('回复');
						$("#hffknr1").show();
						$("#hffknr2").hide();
						$('.hp-btnp-qr').show();
						$('.hp-btnp-qx').show();
						$('.hf').hide();
						ue = UE.getEditor("hffknr",{
							toolbars: [ [ 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', '|', 'forecolor', 'backcolor', '|', 'fontfamily', 'fontsize', '|',
							  			'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', 'preview', 'simpleupload', 'insertvideo', '|', ] ],
							initialFrameWidth : 600,
							initialFrameHeight: 170,
							scaleEnabled: true
						});
						
					}	
				}
    	    })
		},
		saveFknr: function(param){//保存反馈内容
			$.ajax({
				type: "post",
				url: hfckApp.URL.save(),
				data: JSON.stringify(param),
				dataType: "json",
				contentType: "application/json",
				success: function(data){
					if(!data.result){//失败提示
						alert({txt: "反馈处理失败！"});		
					}
					var objs = {txt:"反馈处理成功！",callBackFun:fn}//成功提示：
					success(objs);
					function fn() {location.href = "yjfkgl.html";}
				}
			})
			
		}
	}

	function loadHfck(){
		$.get("../../tpl/fwtgl/yjfkgl-ck-tpl.html", function(template){
			hfckRactive = new Ractive({
				el: ".hp-container",
				template: template,
				oncomplete: function(){
					hfckApp.getYjfkxxById(id,wtzt,hfckRactive);//初始化页面
				}
			})
			hfckRactive.on({
				saveFknr: function(){//回复内容保存
					var param ={id: id,fknr: ue.getContent(),ywy:Constants.YWY.WD_CODE}
					ue.setContent($.trim(param.fknr));
					if($.trim(param.fknr) == ''){
						alert({txt: "回复内容不能为空！"});	
					}else{
						function successCallBackFun(){//确定提交
							hfckApp.saveFknr(param);
						}
						confirm({
							txt: "确认提交吗？",
							successCallBackFun: successCallBackFun
						});	
						
					}
				},
				qx: function(){//取消返回
					location.href = "yjfkgl.html";
				}
			})
		})
	}
	
	return {
		init: function(){
			loadHfck();
		}
	}
}();

$(document).ready(hfck_app.init)